<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        div {
            height: 100px;
            width: 100px;
        }
    </style>
</head>

<body>


    <script>
        function getColor(r,g,b,a) {
            var red = r || 255 ;
            var green = g || 0 ;
            var blue = b || 0 ;
            var alpha = a || 1 ;
            var color = "rgba(" + red + "," + green + "," + blue + "," + alpha  +")";
            return color ;
        }

        var color = getColor();
        console.log(color);
        var str = "<div style='background:"+color+";'></div>";
        // document.write(str);

        // var str = "<div style=' background-color:"+color+";'></div>";

        document.write(str);
    </script>
</body>
</html>